Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ✨ referral app #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

feat: ✨ referral app #6

wants to merge 1 commit into from

Conversation

goztrk
Copy link

@goztrk goztrk commented Jun 16, 2024

No description provided.

class ReferralCode(models.Model):
"""Referral Code model"""

code = models.CharField(max_length=56, unique=True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Always put ForeignKey models that are non-null first.

related_name='referral_codes',
on_delete=models.CASCADE,
)
created_at = models.DateTimeField(auto_now_add=True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add an is_active = models.BooleanFIeld(...) field as well.

We will need to limit the number of referral codes a user can create, otherwise they will just create infinitely many referral codes.

# isort: off


class Referral(models.Model):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AbstractReferral

referrer = models.ForeignKey(
settings.AUTH_USER_MODEL,
related_name='referrals',
on_delete=models.CASCADE,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should have on_delete=models.SET_NULL so that we can show the referral as deactivated or disabled, instead of just vanishing.

referred = models.OneToOneField(
settings.AUTH_USER_MODEL,
related_name='referred_by',
on_delete=models.CASCADE,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should have on_delete=models.SET_NULL so that we can show the referral as deactivated or disabled, instead of just vanishing.

def get_referrer_from_code(referral_code):
referrer = None
if htk_setting('HTK_REFERRAL_ALLOW_USERNAME') and referral_code.startswith(
'@'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if we want this explicitly. Not sure yet.


def get_referrer(request):
referrer = None
key = 'referrer_id'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's put this string in constants.

Let's use an all-caps value.

@@ -0,0 +1,10 @@
# HTK Imports
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Directory name should be plural referrals

HTK_REFERRAL_ALLOW_USERNAME = True

# Redirect URL name for the referral URL
HTK_REFERRAL_REDIRECT_URL_NAME = 'home'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set it to None and require the developer to configure something. If it's not set, redirect to /

def process_response(self, request, response):
if self.referrer:
request.session['referrer_id'] = self.referrer.id
response.set_cookie('referrer_id', self.referrer.id)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use all caps for cookie names; also define a constants file for magic strings

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants